package com.example.royalchef.view;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.royalchef.R;

/**
 * author: Administrator
 * created on: 2017/6/29 11:09
 * description:
 */

public class SettingItemView extends LinearLayout {

    private String sivSettingText;
    private Bitmap sivSettingPicture;

    public SettingItemView(Context context) {
        this(context, null);
        init();
    }

    public SettingItemView(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
        init();
    }

    public SettingItemView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.SettingItemView);
        sivSettingText = typedArray.getString(R.styleable.SettingItemView_siv_setting_text);
        sivSettingPicture = BitmapFactory.decodeResource(getResources(), typedArray.getResourceId(R.styleable.SettingItemView_siv_setting_picture, 0));
        typedArray.recycle();
        init();
    }

    private void init() {
        View inflate = View.inflate(getContext(), R.layout.item_setting, this);
        ImageView ivSettingPicture = (ImageView) inflate.findViewById(R.id.iv_setting_picture);
        TextView tvSettingText = (TextView) inflate.findViewById(R.id.tv_setting_text);
        ivSettingPicture.setImageBitmap(sivSettingPicture);
        tvSettingText.setText(sivSettingText);
    }
}
